package com.jds.test.proto.rsa;

import com.jds.test.proto.aes.AESTest;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToMessageEncoder;

import java.util.List;

/**
 * 客户端用公钥加密
 * Created by joyce on 2019/11/8.
 */
public class MyProtobufClientEncoder extends MessageToMessageEncoder<ByteBuf> {

    @Override
    protected void encode(ChannelHandlerContext channelHandlerContext, ByteBuf byteBuf, List<Object> list) throws Exception {
        byte [] bytes = new byte[byteBuf.readableBytes()];
        byteBuf.readBytes(bytes);
        byte [] encoded = RSACoder.encryptByPublicKey(bytes);
        ByteBuf buf = Unpooled.wrappedBuffer(encoded);
        list.add(buf);

    }
}
